﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// Document
    /// </summary>
    public partial class Document
    {

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="fOrderFiled"></param>
        /// <returns></returns>
        public DataSet GetDocumentListByPage(string tableName, string fields, int pageSize, int pageIndex, string strWhere, string fOrderFiled, int orderType, out int total)
        {
            SqlParameter[] parameters = {  
                    new SqlParameter("@tableName", SqlDbType.VarChar, 50),  
                    new SqlParameter("@fields", SqlDbType.VarChar, 2000),  
                    new SqlParameter("@orderField", SqlDbType.VarChar, 500),  
                    new SqlParameter("@sqlWhere", SqlDbType.VarChar,2000),  
                    new SqlParameter("@pageSize", SqlDbType.Int),  
                    new SqlParameter("@pageIndex", SqlDbType.Int),  
                    new SqlParameter("@orderType", SqlDbType.Int),  
                    new SqlParameter("@TotalPage", SqlDbType.Int),
                    new SqlParameter("@TotalRecordCount", SqlDbType.Int)  
                };

            parameters[0].Value = tableName;
            parameters[1].Value = fields;
            parameters[2].Value = fOrderFiled;
            parameters[3].Value = strWhere;
            parameters[4].Value = pageSize;
            parameters[5].Value = pageIndex;
            parameters[6].Value = orderType;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            DataSet ds = DbHelperSQL.RunProcedure("up_GetRecordByPage", parameters, "ds", 60 * 30);
            total = int.Parse(parameters[8].Value.ToString());
            return ds;
        }

        /// <summary>
        /// 删除信息和附件(事物模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date>
        /// </summary>
        /// <param name="docIdList">信息编号列表</param>
        /// <param name="entityNo">公司编号</param>
        public void DelDocumentAndAttach(List<decimal> docIdList, string entityNo)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();

            //删除信息
            foreach (decimal decDocId in docIdList)
            {
                strSql = new StringBuilder();
                cmds = new CommandInfo();
                strSql.Append("delete from t_document ");
                strSql.Append(" where  FEntityNo=@FEntityNo and FDocId=@FDocId");
                SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocId", SqlDbType.Decimal)};
                parameters[0].Value = entityNo;
                parameters[1].Value = decDocId;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);

                //删除附件                
                strSql = new StringBuilder();
                cmds = new CommandInfo();
                strSql.Append("delete from t_docAttach ");
                strSql.Append(" where FEntityNo=@FEntityNo and FAttachSource=@FAttachSource ");
                SqlParameter[] parameters1 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FAttachSource", SqlDbType.Decimal,9)};
                parameters1[0].Value = entityNo;
                parameters1[1].Value = decDocId;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters1;
                cmdList.Add(cmds);

                strSql = new StringBuilder();
                strSql.Append("delete from t_documentUnionPubEmpl ");
                strSql.Append(" where FDocId=@FDocId and FEntityNo=@FEntityNo");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
                parameters2[0].Value = decDocId;
                parameters2[1].Value = entityNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            DbHelperSQL.ExecuteSqlTranWithIndentity(cmdList);

        }

        /// <summary>
        /// 获得单个Office文件路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decDocId"></param>
        /// <returns></returns>
        public string GetDocSrvFileNameByOffice(string strEntityNo, decimal decDocId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FSvrFileName from t_document ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId=@FDocId ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocId", SqlDbType.Decimal)};
            parameters[0].Value = strEntityNo;
            parameters[1].Value = decDocId;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    return sdr[0].ToString();
                }
            }

            return "";
        }

        /// <summary>
        /// 获得多个Office文件路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decDocId"></param>
        /// <returns></returns>
        public List<string> GetDocSrvFileNameByOffice(string strEntityNo, string strDocIdS)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FSvrFileName from t_document ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId in(");
            strSql.Append(strDocIdS);
            strSql.Append(")");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                }
            }

            return listStr;
        }

        /// <summary>
        /// 获取某个员工所有放入回收站的信息的ID FRecycle='Y'
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <returns></returns>
        public List<decimal> GetDocIDByFRecycle(string strEntityNo, string strEmplNo)
        {
            List<decimal> listDecId = new List<decimal>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select fdocid from t_document where FRecycle='Y' and FEntityNo=@FEntityNo and FEmplNo=@FEmplNo");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = strEntityNo;
            parameters[1].Value = strEmplNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listDecId.Add(decimal.Parse(sdr[0].ToString()));
                }
            }
            return listDecId;
        }


        /// <summary>
        /// 获取多条记录的附件路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decAttachSource"></param>
        /// <param name="strAttachType"></param>
        /// <returns></returns>
        public List<string> GetDocAttachS(string strEntityNo, string strAttachSourceS, string strAttachType)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAttachSvrFileName from t_docAttach where FEntityNo=@FEntityNo and FAttachType=@FAttachType");
            strSql.Append(" and FAttachSource in(");
            strSql.Append(strAttachSourceS);
            strSql.Append(")");
            SqlParameter[] parameters = {					
					new SqlParameter("@FAttachType", SqlDbType.NVarChar,80),			
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = strAttachType;
            parameters[1].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                }
            }

            return listStr;
        }

        /// <summary>
        /// 获取单条记录的附件路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decAttachSource"></param>
        /// <param name="strAttachType"></param>
        /// <returns></returns>
        public List<string> GetDocAttachS(string strEntityNo, decimal decAttachSource, string strAttachType)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAttachSvrFileName from t_docAttach where FAttachSource=@FAttachSource and FEntityNo=@FEntityNo and FAttachType=@FAttachType");
            SqlParameter[] parameters = {					
					new SqlParameter("@FAttachType", SqlDbType.NVarChar,80),
					new SqlParameter("@FAttachSource", SqlDbType.Decimal,9),				
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = strAttachType;
            parameters[1].Value = decAttachSource;
            parameters[2].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                }
            }

            return listStr;
        }

        /// <summary>
        /// 获得多个缩略图路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decDocId"></param>
        /// <returns></returns>
        public List<string> GetDocFThumbSrvFileName(string strEntityNo, string strDocIdS)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FThumbSrvFileName from t_document ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId in(");
            strSql.Append(strDocIdS);
            strSql.Append(")");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                }
            }

            return listStr;
        }

        /// <summary>
        /// 获得单个缩略图路径
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decDocId"></param>
        /// <returns></returns>
        public string GetDocFThumbSrvFileName(string strEntityNo, decimal decDocId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FThumbSrvFileName from t_document ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId=@FDocId ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
					new SqlParameter("@FDocId", SqlDbType.Decimal)};
            parameters[0].Value = strEntityNo;
            parameters[1].Value = decDocId;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                if (sdr.Read())
                {
                    return sdr[0].ToString();
                }
            }

            return "";
        }

        /// <summary>
        /// 获取计划总结上报情况
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public DataSet GetPlanSummaryReport(string year)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT * FROM v_PlanSummaryReport
                                    WHERE years=@years
                                    ORDER BY a.FDeptNo, years,months,dayss");
            SqlParameter[] parameters = {
                    new SqlParameter("@years", SqlDbType.VarChar,50)};
            parameters[0].Value = year;

            return  DbHelperSQL.Query(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 获取所有的年份，按年份降序
        /// <creator>zhongyl</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <returns></returns>
        public DataSet GetYeat(string strEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT YEAR(FPubDate) as FYear
  FROM [ElingOA6_Admin_DSJCJ].[dbo].[t_document] GROUP BY YEAR(FPubDate) ORDER BY YEAR(FPubDate)");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = strEntityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 信息还原
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        /// <param name="docIdList">信息编号</param>
        public void UpdateDocRestore(List<decimal> docIdList)
        {
            List<CommandInfo> commandInfoList = new List<CommandInfo>();
            CommandInfo commandInfo = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };
            foreach (decimal docId in docIdList)
            {
                strSql = new StringBuilder();
                strSql.Append("UPDATE t_document SET FRecycle='N',FDelEmplNo=NULL,FDelDate=NULL");
                strSql.Append(" WHERE FDocId=@FDocId");
                parameters = new SqlParameter[] { 	
					new SqlParameter("@FDocId", SqlDbType.Decimal)};
                parameters[0].Value = docId;

                commandInfo = new CommandInfo(strSql.ToString(), parameters);
                commandInfoList.Add(commandInfo);
            }
            if (commandInfoList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(commandInfoList);
            }
        }

        /// <summary>
        /// 根据信息编号获取信息条数
        /// <creator>wangl</creator>
        /// <date>2013-07-22</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns></returns>
        public int GetDocCountByDocClsCd(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from t_document");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocClsCd=@FDocClsCd");
            SqlParameter[] parameters = {
                    new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return Int32.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 根据信息编号获取信息编号(适用于单信息)
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date> 
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns></returns>
        public decimal GetDocIdDocClsCd(string entityNo, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FDocId from t_document");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocClsCd=@FDocClsCd");
            SqlParameter[] parameters = {
                    new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return decimal.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 获取文档实体类
        /// <creator>wangl</creator>
        /// <date>2013-08-07</date> 
        /// </summary>
        /// <param name="docId">文档编号</param>
        /// <returns>文档实体类</returns>
        public Model.Document GetModel(decimal docId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  top 1 FDocId,FDocClsCd,FEntityNo,FDocSrcName,FPubDate,FPubIp,FTitle,FSubTitle,FContentTxt,FContentBin,FSvrFileName,FAuthor,FReadCnt,FThumbGenType,FThumbContent,FThumbFileExt,FThumbSrvFileName,FThumbOldFileName,FThumbSeqID,FEditMode,FIsTop,FTopSeq,FIsEnroll,FStatus,FIsShowHomePage,FDeptNo,FEmplNo,FAuditDeptNo,FAuditEmpNo,FValidDate,FReferenceNo,FWorkGrpNo,FAuditDate,FAuditIP,FUpdDeptNo,FUpdEmplNo,FUpdDate,FUpdIP,FRecycle,FDelEmplNo,FDelDate,FIsPubJCMS,FParallelDocClsCd,FExamineDeptNo,FExamineEmpNo,FExamineDate,FExamineIP,FExamineContent,FExamineCase,FCaseMemo,FSuperiorApply,FSuperiorApplyMemo,FContentIsImg,IsToFinancePlat,IsToIntranetPlat,FDownTitle ,FDownDateString from t_document ");
            strSql.Append(" WHERE FDocId=@FDocId ");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal)};
            parameters[0].Value = docId;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        ///  保存信息同时保存附件,通知对象(事务模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-13</date> 
        /// </summary>
        /// <param name="documentModel">信息实体类</param>
        /// <param name="docAttachList">附件列表</param>
        /// <param name="docRecObjectList">通知对象列表</param>
        /// <param name="imgNewPath">文件新名称</param>
        /// <param name="extenSion">扩展名</param>
        /// <param name="documentUnionPubEmplList">合发部门列表</param>
        /// <param name="docReferenceList ">呈送信息栏目列表</param>
        /// <returns>文档编号</returns>
        public decimal SaveDocumentAndAttach(Model.Document documentModel, List<Model.DocAttach> docAttachList, List<Model.DocRecObject> docRecObjectList,
            string imgNewPath, string extenSion, List<Model.DocumentUnionPubEmpl> documentUnionPubEmplList, List<Model.DocReference> docReferenceList,
            List<Model.documentAuthority> documentAuthorityList)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();


            //增加信息内容
            strSql.Append("insert into t_document(");
            strSql.Append("FDocClsCd,FEntityNo,FDocSrcName,FPubDate,FPubIp,FTitle,FSubTitle,FContentTxt,FContentBin,FSvrFileName,FAuthor,FReadCnt,FThumbGenType,FThumbContent,FThumbFileExt,FThumbSrvFileName,FThumbOldFileName,FThumbSeqID,FEditMode,FIsTop,FTopSeq,FIsEnroll,FStatus,FIsShowHomePage,FDeptNo,FEmplNo,FAuditDeptNo,FAuditEmpNo,FValidDate,FReferenceNo,FWorkGrpNo,FAuditDate,FAuditIP,FUpdDeptNo,FUpdEmplNo,FUpdDate,FUpdIP,FRecycle,FIsPubJCMS,FParallelDocClsCd,FContentIsImg,IsToFinancePlat,IsToIntranetPlat,FDownTitle ,FDownDateString)");
            strSql.Append(" values (");
            strSql.Append("@FDocClsCd,@FEntityNo,@FDocSrcName,@FPubDate,@FPubIp,@FTitle,@FSubTitle,@FContentTxt,@FContentBin,");
            if (imgNewPath != "")
            {
                strSql.Append("'" + imgNewPath + documentModel.FEntityNo + "_' + " + "cast(IDENT_CURRENT('t_document') as varchar(20))" + " + '_" + extenSion + "'");

            }
            else
            {
                strSql.Append("''");
            }
            strSql.Append(",@FAuthor,@FReadCnt,@FThumbGenType,@FThumbContent,@FThumbFileExt,@FThumbSrvFileName,@FThumbOldFileName,@FThumbSeqID,@FEditMode,@FIsTop,@FTopSeq,@FIsEnroll,@FStatus,@FIsShowHomePage,@FDeptNo,@FEmplNo,@FAuditDeptNo,@FAuditEmpNo,@FValidDate,@FReferenceNo,@FWorkGrpNo,@FAuditDate,@FAuditIP,@FUpdDeptNo,@FUpdEmplNo,@FUpdDate,@FUpdIP,@FRecycle,@FIsPubJCMS,@FParallelDocClsCd,@FContentIsImg,@IsToFinancePlat,@IsToIntranetPlat,@FDownTitle ,@FDownDateString)");
            strSql.Append(";select @returnBId=IDENT_CURRENT('t_document')");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDocSrcName", SqlDbType.VarChar,80),
					new SqlParameter("@FPubDate", SqlDbType.DateTime),
					new SqlParameter("@FPubIp", SqlDbType.VarChar,15),
					new SqlParameter("@FTitle", SqlDbType.VarChar,255),
					new SqlParameter("@FSubTitle", SqlDbType.VarChar,255),
					new SqlParameter("@FContentTxt", SqlDbType.Text),
					new SqlParameter("@FContentBin", SqlDbType.Image),
					new SqlParameter("@FAuthor", SqlDbType.VarChar,100),
					new SqlParameter("@FReadCnt", SqlDbType.Int,4),
					new SqlParameter("@FThumbGenType", SqlDbType.Char,1),
					new SqlParameter("@FThumbContent", SqlDbType.Image),
					new SqlParameter("@FThumbFileExt", SqlDbType.VarChar,80),
					new SqlParameter("@FThumbSrvFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FThumbOldFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FThumbSeqID", SqlDbType.Int,4),
					new SqlParameter("@FEditMode", SqlDbType.Char,1),
					new SqlParameter("@FIsTop", SqlDbType.Int,4),
					new SqlParameter("@FTopSeq", SqlDbType.Int,4),
					new SqlParameter("@FIsEnroll", SqlDbType.VarChar,1),
					new SqlParameter("@FStatus", SqlDbType.VarChar,1),
					new SqlParameter("@FIsShowHomePage", SqlDbType.VarChar,1),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FAuditDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuditEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FValidDate", SqlDbType.DateTime),
					new SqlParameter("@FReferenceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FWorkGrpNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuditDate", SqlDbType.DateTime),
					new SqlParameter("@FAuditIP", SqlDbType.VarChar,15),
                    new SqlParameter("@returnBId", SqlDbType.Decimal),
                    new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
                    new SqlParameter("@FRecycle", SqlDbType.Char,1),
                    new SqlParameter("@FIsPubJCMS", SqlDbType.Char,1),
                    new SqlParameter("@FParallelDocClsCd", SqlDbType.NVarChar,25),
                    new SqlParameter("@FContentIsImg", SqlDbType.Char,1),
                    new SqlParameter("@IsToFinancePlat",SqlDbType.NVarChar,1),
                    new SqlParameter("@IsToIntranetPlat",SqlDbType.NVarChar,1),
                    new SqlParameter("@FDownTitle",SqlDbType.NVarChar,50),
                    new SqlParameter("@FDownDateString",SqlDbType.NVarChar,20)
                                        };
            parameters[0].Value = documentModel.FDocClsCd;
            parameters[1].Value = documentModel.FEntityNo;
            parameters[2].Value = documentModel.FDocSrcName;
            parameters[3].Value = documentModel.FPubDate;
            parameters[4].Value = documentModel.FPubIp;
            parameters[5].Value = documentModel.FTitle;
            parameters[6].Value = documentModel.FSubTitle;
            parameters[7].Value = documentModel.FContentTxt;
            parameters[8].Value = documentModel.FContentBin;
            parameters[9].Value = documentModel.FAuthor;
            parameters[10].Value = documentModel.FReadCnt;
            parameters[11].Value = documentModel.FThumbGenType;
            parameters[12].Value = documentModel.FThumbContent;
            parameters[13].Value = documentModel.FThumbFileExt;
            parameters[14].Value = documentModel.FThumbSrvFileName;
            parameters[15].Value = documentModel.FThumbOldFileName;
            parameters[16].Value = documentModel.FThumbSeqID;
            parameters[17].Value = documentModel.FEditMode;
            parameters[18].Value = documentModel.FIsTop;
            parameters[19].Value = documentModel.FTopSeq;
            parameters[20].Value = documentModel.FIsEnroll;
            parameters[21].Value = documentModel.FStatus;
            parameters[22].Value = documentModel.FIsShowHomePage;
            parameters[23].Value = documentModel.FDeptNo;
            parameters[24].Value = documentModel.FEmplNo;
            parameters[25].Value = documentModel.FAuditDeptNo;
            parameters[26].Value = documentModel.FAuditEmpNo;
            parameters[27].Value = documentModel.FValidDate;
            parameters[28].Value = documentModel.FReferenceNo;
            parameters[29].Value = documentModel.FWorkGrpNo;
            parameters[30].Value = documentModel.FAuditDate;
            parameters[31].Value = documentModel.FAuditIP;
            parameters[32].Direction = ParameterDirection.Output;
            parameters[33].Value = documentModel.FUpdDeptNo;
            parameters[34].Value = documentModel.FUpdEmplNo;
            parameters[35].Value = documentModel.FUpdDate;
            parameters[36].Value = documentModel.FUpdIP;
            parameters[37].Value = documentModel.FRecycle;
            parameters[38].Value = documentModel.FIsPubJCMS;
            parameters[39].Value = documentModel.FParallelDocClsCd;
            parameters[40].Value = documentModel.FContentIsImg;
            parameters[41].Value = documentModel.IsToFinancePlat;
            parameters[42].Value = documentModel.IsToIntranetPlat;
            parameters[43].Value = documentModel.FDownTitle;
            parameters[44].Value = documentModel.FDownDateString;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //增加附件
            if (docAttachList.Count > 0)
            {
                foreach (Model.DocAttach attachObject in docAttachList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_docAttach(");
                    strSql.Append("FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachType,FAttachSource,FAttachFileExt,FEntityNo,FAttachOldFileName)");
                    strSql.Append(" values (");
                    strSql.Append("@FAttachSvrFileName,@FAttachDesc,@FAttachContent,@FAttachType,@returnBId,@FAttachFileExt,@FEntityNo,@FAttachOldFileName)");
                    strSql.Append(";select IDENT_CURRENT('t_docAttach')");
                    SqlParameter[] parameters1 = {
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachContent", SqlDbType.Image),
					new SqlParameter("@FAttachType", SqlDbType.NVarChar,80),
					new SqlParameter("@returnBId", SqlDbType.Decimal,9),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255)};
                    parameters1[0].Value = attachObject.FAttachSvrFileName;
                    parameters1[1].Value = attachObject.FAttachDesc;
                    //parameters1[2].Value = attachObject.FAttachContent;
                    parameters1[2].Value = DBNull.Value;
                    parameters1[3].Value = attachObject.FAttachType;
                    parameters1[4].Direction = ParameterDirection.InputOutput;
                    parameters1[5].Value = attachObject.FAttachFileExt;
                    parameters1[6].Value = attachObject.FEntityNo;
                    parameters1[7].Value = attachObject.FAttachOldFileName;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters1;
                    cmdList.Add(cmds);
                }
            }

            //增加通知对象
            if (docRecObjectList.Count > 0)
            {
                foreach (Model.DocRecObject docRecObject in docRecObjectList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_docRecObject(");
                    strSql.Append("FDocId,FEntityNo,FDeptNo,FEmplNo,FWorkGrpNo)");
                    strSql.Append(" values (");
                    strSql.Append("@returnBId,@FEntityNo,@FDeptNo,@FEmplNo,@FWorkGrpNo)");
                    SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId", SqlDbType.Decimal,9),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FWorkGrpNo", SqlDbType.NVarChar,12)};
                    parameters2[0].Direction = ParameterDirection.InputOutput;
                    parameters2[1].Value = docRecObject.FEntityNo;
                    parameters2[2].Value = docRecObject.FDeptNo;
                    parameters2[3].Value = docRecObject.FEmplNo;
                    parameters2[4].Value = docRecObject.FWorkGrpNo;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters2;
                    cmdList.Add(cmds);
                }
            }


            //增加合发部门
            if (documentUnionPubEmplList.Count > 0)
            {
                foreach (Model.DocumentUnionPubEmpl docUnionPubEmplModel in documentUnionPubEmplList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_documentUnionPubEmpl(");
                    strSql.Append("FDocId,FEntityNo,FDeptNo,FEmplNo)");
                    strSql.Append(" values (");
                    strSql.Append("@returnBId,@FEntityNo,@FDeptNo,@FEmplNo)");
                    SqlParameter[] parameters6 = {
                            new SqlParameter("@returnBId", SqlDbType.Decimal,9),
                            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters6[0].Direction = ParameterDirection.InputOutput;
                    parameters6[1].Value = documentModel.FEntityNo;
                    parameters6[2].Value = docUnionPubEmplModel.FDeptNo;
                    parameters6[3].Value = docUnionPubEmplModel.FEmplNo;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters6;
                    cmdList.Add(cmds);
                }
            }
            //增加呈送信息栏目
            if (docReferenceList.Count > 0)
            {
                foreach (Model.DocReference docReferenceModel in docReferenceList)
                {
                    if (docReferenceModel.FDocClsCd == documentModel.FDocClsCd)
                    {
                        continue;
                    }

                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_DocReference(");
                    strSql.Append("FDocId,FEntityNo,FDocClsCd)");
                    strSql.Append(" values (");
                    strSql.Append("@returnBId,@FEntityNo,@FDocClsCd)");
                    SqlParameter[] parameters7 = {
                            new SqlParameter("@returnBId", SqlDbType.Decimal,9),
                            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25)};
                    parameters7[0].Direction = ParameterDirection.InputOutput;
                    parameters7[1].Value = documentModel.FEntityNo;
                    parameters7[2].Value = docReferenceModel.FDocClsCd; ;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters7;
                    cmdList.Add(cmds);
                }
            }

            //文档查看权限
            //添加新的权限语句
            if (documentAuthorityList.Count > 0)
            {
                foreach (Model.documentAuthority documentAuthorityModel in documentAuthorityList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_documentAuthority(");
                    strSql.Append("FPronoun,FDocId,FSourceNo,FProp)");
                    strSql.Append(" values (");
                    strSql.Append("@FPronoun,@returnBId,@FSourceNo,@FProp)");
                    parameters = new SqlParameter[] {
					new SqlParameter("@FPronoun", SqlDbType.NVarChar,25),
					new SqlParameter("@returnBId", SqlDbType.Decimal,9),
					new SqlParameter("@FSourceNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FProp", SqlDbType.Char,1)};
                    parameters[0].Value = documentAuthorityModel.FPronoun;
                    parameters[1].Direction = ParameterDirection.InputOutput;
                    parameters[2].Value = documentAuthorityModel.FSourceNo;
                    parameters[3].Value = documentAuthorityModel.FProp;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }

            //执行存储过程，生成临时表数据，以便查询时调用 
            strSql = new StringBuilder();
            cmds = new CommandInfo();
            strSql.Append("EXEC sp_genDocumnetAuthorityDW ");

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = new SqlParameter[] { };
            cmdList.Add(cmds);


            DbHelperSQL.ExecuteSqlTranWithIndentity(cmdList, 30 * 60);
            return decimal.Parse(cmdList[0].Parameters[32].Value.ToString());

        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.Document DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.Document model = new ElingOA6_Admin_DSJCJ.Model.Document();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                //if (row["FDocSrcName"] != null)
                //{
                //    model.FDocSrcName = row["FDocSrcName"].ToString();
                //}
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                if (row["FPubIp"] != null)
                {
                    model.FPubIp = row["FPubIp"].ToString();
                }
                if (row["FTitle"] != null)
                {
                    model.FTitle = row["FTitle"].ToString();
                }
                if (row["FSubTitle"] != null)
                {
                    model.FSubTitle = row["FSubTitle"].ToString();
                }
                if (row["FContentTxt"] != null)
                {
                    model.FContentTxt = row["FContentTxt"].ToString();
                }
                if (row["FContentBin"] != null && row["FContentBin"].ToString() != "")
                {
                    model.FContentBin = (byte[])row["FContentBin"];
                }
                if (row["FSvrFileName"] != null)
                {
                    model.FSvrFileName = row["FSvrFileName"].ToString();
                }
                if (row["FAuthor"] != null)
                {
                    model.FAuthor = row["FAuthor"].ToString();
                }
                if (row["FReadCnt"] != null && row["FReadCnt"].ToString() != "")
                {
                    model.FReadCnt = int.Parse(row["FReadCnt"].ToString());
                }
                if (row["FThumbGenType"] != null)
                {
                    model.FThumbGenType = row["FThumbGenType"].ToString();
                }
                if (row["FThumbContent"] != null && row["FThumbContent"].ToString() != "")
                {
                    model.FThumbContent = (byte[])row["FThumbContent"];
                }
                if (row["FThumbFileExt"] != null)
                {
                    model.FThumbFileExt = row["FThumbFileExt"].ToString();
                }
                if (row["FThumbSrvFileName"] != null)
                {
                    model.FThumbSrvFileName = row["FThumbSrvFileName"].ToString();
                }
                if (row["FThumbOldFileName"] != null)
                {
                    model.FThumbOldFileName = row["FThumbOldFileName"].ToString();
                }
                if (row["FThumbSeqID"] != null && row["FThumbSeqID"].ToString() != "")
                {
                    model.FThumbSeqID = int.Parse(row["FThumbSeqID"].ToString());
                }
                if (row["FEditMode"] != null)
                {
                    model.FEditMode = row["FEditMode"].ToString();
                }
                if (row["FIsTop"] != null && row["FIsTop"].ToString() != "")
                {
                    model.FIsTop = int.Parse(row["FIsTop"].ToString());
                }
                if (row["FTopSeq"] != null && row["FTopSeq"].ToString() != "")
                {
                    model.FTopSeq = int.Parse(row["FTopSeq"].ToString());
                }
                if (row["FIsEnroll"] != null)
                {
                    model.FIsEnroll = row["FIsEnroll"].ToString();
                }
                if (row["FStatus"] != null)
                {
                    model.FStatus = row["FStatus"].ToString();
                }
                if (row["FIsShowHomePage"] != null)
                {
                    model.FIsShowHomePage = row["FIsShowHomePage"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FAuditDeptNo"] != null)
                {
                    model.FAuditDeptNo = row["FAuditDeptNo"].ToString();
                }
                if (row["FAuditEmpNo"] != null)
                {
                    model.FAuditEmpNo = row["FAuditEmpNo"].ToString();
                }
                if (row["FValidDate"] != null && row["FValidDate"].ToString() != "")
                {
                    model.FValidDate = DateTime.Parse(row["FValidDate"].ToString());
                }
                if (row["FReferenceNo"] != null)
                {
                    model.FReferenceNo = row["FReferenceNo"].ToString();
                }
                if (row["FWorkGrpNo"] != null)
                {
                    model.FWorkGrpNo = row["FWorkGrpNo"].ToString();
                }
                if (row["FAuditDate"] != null && row["FAuditDate"].ToString() != "")
                {
                    model.FAuditDate = DateTime.Parse(row["FAuditDate"].ToString());
                }
                if (row["FAuditIP"] != null)
                {
                    model.FAuditIP = row["FAuditIP"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row["FRecycle"] != null)
                {
                    model.FRecycle = row["FRecycle"].ToString();
                }
                if (row["FDelEmplNo"] != null)
                {
                    model.FDelEmplNo = row["FDelEmplNo"].ToString();
                }
                if (row["FDelDate"] != null && row["FDelDate"].ToString() != "")
                {
                    model.FDelDate = DateTime.Parse(row["FDelDate"].ToString());
                }
                if (row["FIsPubJCMS"] != null)
                {
                    model.FIsPubJCMS = row["FIsPubJCMS"].ToString();
                }
                if (row["FParallelDocClsCd"] != null)
                {
                    model.FParallelDocClsCd = row["FParallelDocClsCd"].ToString();
                }
                if (row["FExamineDeptNo"] != null)
                {
                    model.FExamineDeptNo = row["FExamineDeptNo"].ToString();
                }
                if (row["FExamineEmpNo"] != null)
                {
                    model.FExamineEmpNo = row["FExamineEmpNo"].ToString();
                }
                if (row["FExamineDate"] != null && row["FExamineDate"].ToString() != "")
                {
                    model.FExamineDate = DateTime.Parse(row["FExamineDate"].ToString());
                }
                if (row["FExamineIP"] != null)
                {
                    model.FExamineIP = row["FExamineIP"].ToString();
                }
                if (row["FExamineContent"] != null)
                {
                    model.FExamineContent = row["FExamineContent"].ToString();
                }
                if (row["FExamineCase"] != null)
                {
                    model.FExamineCase = row["FExamineCase"].ToString();
                }
                if (row["FCaseMemo"] != null)
                {
                    model.FCaseMemo = row["FCaseMemo"].ToString();
                }
                if (row["FSuperiorApply"] != null)
                {
                    model.FSuperiorApply = row["FSuperiorApply"].ToString();
                }
                if (row["FSuperiorApplyMemo"] != null)
                {
                    model.FSuperiorApplyMemo = row["FSuperiorApplyMemo"].ToString();
                }
                if (row["FContentIsImg"] != null)
                {
                    model.FContentIsImg = row["FContentIsImg"].ToString();
                }
                if (row.Table.Columns.Contains("IsToFinancePlat"))
                {
                    if (row["IsToFinancePlat"] != null)
                    {
                        model.IsToFinancePlat = row["IsToFinancePlat"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("IsToIntranetPlat"))
                {
                    if (row["IsToIntranetPlat"] != null)
                    {
                        model.IsToIntranetPlat = row["IsToIntranetPlat"].ToString();
                    }
                }
                 if (row.Table.Columns.Contains("FDownTitle"))
                {
                    if (row["FDownTitle"] != null)
                    {
                        model.FDownTitle = row["FDownTitle"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FDownDateString"))
                {
                    if (row["FDownDateString"] != null)
                    {
                        model.FDownDateString = row["FDownDateString"].ToString();
                    }
                }
            }
            return model;
        }
        /// <summary>
        /// 修改信息和附件,通知对象，包括信息置顶改变修改相应置顶信息(事物模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-15</date> 
        /// </summary>
        /// <param name="documentModel">信息实体类</param>
        /// <param name="docAttachList">附件列表</param>
        /// <param name="docRecObjectList">通知对象列表</param>
        /// <param name="isTop">是否置顶</param>
        /// <param name="documentUnionPubEmplList">合发部门列表</param>
        /// <param name="docReferenceList ">呈送信息栏目列表</param>
        public void UpdateDocAndAttach(Model.Document documentModel, List<Model.DocAttach> docAttachList,
            List<Model.DocRecObject> docRecObjectList, string isTop, List<Model.DocumentUnionPubEmpl> documentUnionPubEmplList, List<Model.DocReference> docReferenceList,
            List<Model.documentAuthority> documentAuthorityList)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();

            //修改置顶
            if (isTop == "TOP")//由未置顶改为置顶
            {
                strSql.Append("update t_document set ");
                strSql.Append("FTopSeq=FTopSeq+1 ");
                strSql.Append(" where FEntityNo=@FEntityNo and FIsTop=1 and FDocClsCd=@FDocClsCd");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25)};
                parameters2[0].Value = documentModel.FEntityNo;
                parameters2[1].Value = documentModel.FDocClsCd;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }


            strSql = new StringBuilder();
            cmds = new CommandInfo();

            //修改信息
            strSql.Append("update t_document set ");
            strSql.Append("FDocSrcName=@FDocSrcName,");
            strSql.Append("FTitle=@FTitle,");
            strSql.Append("FSubTitle=@FSubTitle,");
            strSql.Append("FContentTxt=@FContentTxt,");
            strSql.Append("FContentBin=@FContentBin,");
            strSql.Append("FSvrFileName=@FSvrFileName,");
            strSql.Append("FAuthor=@FAuthor,");
            //strSql.Append("FReadCnt=@FReadCnt,");
            strSql.Append("FThumbGenType=@FThumbGenType,");
            strSql.Append("FThumbContent=@FThumbContent,");
            strSql.Append("FThumbFileExt=@FThumbFileExt,");
            strSql.Append("FThumbSrvFileName=@FThumbSrvFileName,");
            strSql.Append("FThumbOldFileName=@FThumbOldFileName,");
            strSql.Append("FThumbSeqID=@FThumbSeqID,");
            strSql.Append("FEditMode=@FEditMode,");
            strSql.Append("FIsTop=@FIsTop,");
            strSql.Append("FTopSeq=@FTopSeq,");
            strSql.Append("FIsEnroll=@FIsEnroll,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FIsShowHomePage=@FIsShowHomePage,");
            strSql.Append("FAuditDeptNo=@FAuditDeptNo,");
            strSql.Append("FAuditEmpNo=@FAuditEmpNo,");
            strSql.Append("FValidDate=@FValidDate,");
            strSql.Append("FReferenceNo=@FReferenceNo,");
            strSql.Append("FWorkGrpNo=@FWorkGrpNo,");
            strSql.Append("FAuditDate=@FAuditDate,");
            strSql.Append("FAuditIP=@FAuditIP,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP,");
            strSql.Append("FRecycle=@FRecycle,");
            strSql.Append("FIsPubJCMS=@FIsPubJCMS,");
            strSql.Append("FParallelDocClsCd=@FParallelDocClsCd,");
            strSql.Append("FExamineCase=@FExamineCase,");
            strSql.Append("FCaseMemo=@FCaseMemo,");
            strSql.Append("FSuperiorApply=@FSuperiorApply,");
            strSql.Append("FSuperiorApplyMemo=@FSuperiorApplyMemo,");
            strSql.Append("FContentIsImg=@FContentIsImg,");
            strSql.Append("IsToFinancePlat=@IsToFinancePlat,");
            strSql.Append("IsToIntranetPlat=@IsToIntranetPlat,");
            strSql.Append("FDownTitle=@FDownTitle,");
            strSql.Append("FDownDateString=@FDownDateString");
            strSql.Append(" where FDocClsCd=@FDocClsCd and FEntityNo=@FEntityNo and FDocId=@FDocId ");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDocSrcName", SqlDbType.VarChar,80),
                    new SqlParameter("@FContentIsImg", SqlDbType.Char,1),
					new SqlParameter("@FTitle", SqlDbType.VarChar,255),
					new SqlParameter("@FSubTitle", SqlDbType.VarChar,255),
					new SqlParameter("@FContentTxt", SqlDbType.Text),
					new SqlParameter("@FContentBin", SqlDbType.Image),
					new SqlParameter("@FSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAuthor", SqlDbType.VarChar,100),
					//new SqlParameter("@FReadCnt", SqlDbType.Int,4),
					new SqlParameter("@FThumbGenType", SqlDbType.Char,1),
					new SqlParameter("@FThumbContent", SqlDbType.Image),
					new SqlParameter("@FThumbFileExt", SqlDbType.VarChar,80),
					new SqlParameter("@FThumbSrvFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FThumbOldFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FThumbSeqID", SqlDbType.Int,4),
					new SqlParameter("@FEditMode", SqlDbType.Char,1),
					new SqlParameter("@FIsTop", SqlDbType.Int,4),
					new SqlParameter("@FTopSeq", SqlDbType.Int,4),
					new SqlParameter("@FIsEnroll", SqlDbType.VarChar,1),
					new SqlParameter("@FStatus", SqlDbType.VarChar,1),
					new SqlParameter("@FIsShowHomePage", SqlDbType.VarChar,1),
					new SqlParameter("@FAuditDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuditEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FValidDate", SqlDbType.DateTime),
					new SqlParameter("@FReferenceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FWorkGrpNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAuditDate", SqlDbType.DateTime),
					new SqlParameter("@FAuditIP", SqlDbType.VarChar,15),
                    new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
                    new SqlParameter("@FRecycle", SqlDbType.Char,1),
                    new SqlParameter("@FIsPubJCMS", SqlDbType.Char,1),
                    new SqlParameter("@FParallelDocClsCd", SqlDbType.NVarChar,25),
                    new SqlParameter("@FExamineCase", SqlDbType.Char,1),
                    new SqlParameter("@FCaseMemo", SqlDbType.NVarChar,255),
                    new SqlParameter("@FSuperiorApply", SqlDbType.Char,1),
                    new SqlParameter("@FSuperiorApplyMemo", SqlDbType.NVarChar,255),
                    new SqlParameter("@IsToFinancePlat",SqlDbType.NVarChar,1),
                    new SqlParameter("@IsToIntranetPlat",SqlDbType.NVarChar,1),
                     new SqlParameter("@FDownTitle",SqlDbType.NVarChar,50),
                    new SqlParameter("@FDownDateString",SqlDbType.NVarChar,20)
                   };
            parameters[0].Value = documentModel.FDocId;
            parameters[1].Value = documentModel.FDocClsCd;
            parameters[2].Value = documentModel.FEntityNo;
            parameters[3].Value = documentModel.FDocSrcName;
            parameters[4].Value = documentModel.FContentIsImg;
            parameters[5].Value = documentModel.FTitle;
            parameters[6].Value = documentModel.FSubTitle;
            parameters[7].Value = documentModel.FContentTxt;
            parameters[8].Value = documentModel.FContentBin;
            parameters[9].Value = documentModel.FSvrFileName;
            parameters[10].Value = documentModel.FAuthor;
            //parameters[11].Value = documentModel.FReadCnt;
            parameters[11].Value = documentModel.FThumbGenType;
            parameters[12].Value = documentModel.FThumbContent;
            parameters[13].Value = documentModel.FThumbFileExt;
            parameters[14].Value = documentModel.FThumbSrvFileName;
            parameters[15].Value = documentModel.FThumbOldFileName;
            parameters[16].Value = documentModel.FThumbSeqID;
            parameters[17].Value = documentModel.FEditMode;
            parameters[18].Value = documentModel.FIsTop;
            parameters[19].Value = documentModel.FTopSeq;
            parameters[20].Value = documentModel.FIsEnroll;
            parameters[21].Value = documentModel.FStatus;
            parameters[22].Value = documentModel.FIsShowHomePage;
            parameters[23].Value = documentModel.FAuditDeptNo;
            parameters[24].Value = documentModel.FAuditEmpNo;
            parameters[25].Value = documentModel.FValidDate;
            parameters[26].Value = documentModel.FReferenceNo;
            parameters[27].Value = documentModel.FWorkGrpNo;
            parameters[28].Value = documentModel.FAuditDate;
            parameters[29].Value = documentModel.FAuditIP;
            parameters[30].Value = documentModel.FUpdDeptNo;
            parameters[31].Value = documentModel.FUpdEmplNo;
            parameters[32].Value = documentModel.FUpdDate;
            parameters[33].Value = documentModel.FUpdIP;
            parameters[34].Value = documentModel.FRecycle;
            parameters[35].Value = documentModel.FIsPubJCMS;
            parameters[36].Value = documentModel.FParallelDocClsCd;
            parameters[37].Value = documentModel.FExamineCase;
            parameters[38].Value = documentModel.FCaseMemo;
            parameters[39].Value = documentModel.FSuperiorApply;
            parameters[40].Value = documentModel.FSuperiorApplyMemo;
            parameters[41].Value = documentModel.IsToFinancePlat;
            parameters[42].Value = documentModel.IsToIntranetPlat;
            parameters[43].Value = documentModel.FDownTitle;
            parameters[44].Value = documentModel.FDownDateString;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //增加附件
            if (docAttachList.Count > 0)
            {
                foreach (Model.DocAttach attachObject in docAttachList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_docAttach(");
                    strSql.Append("FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachType,FAttachSource,FAttachFileExt,FEntityNo,FAttachOldFileName)");
                    strSql.Append(" values (");
                    strSql.Append("@FAttachSvrFileName,@FAttachDesc,@FAttachContent,@FAttachType,@returnBId,@FAttachFileExt,@FEntityNo,@FAttachOldFileName)");
                    strSql.Append(";select IDENT_CURRENT('t_docAttach')");
                    SqlParameter[] parameters1 = {
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachContent", SqlDbType.Image),
					new SqlParameter("@FAttachType", SqlDbType.NVarChar,80),
					new SqlParameter("@returnBId", SqlDbType.Decimal,9),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255)};
                    parameters1[0].Value = attachObject.FAttachSvrFileName;
                    parameters1[1].Value = attachObject.FAttachDesc;
                    //parameters1[2].Value = attachObject.FAttachContent;
                    parameters1[2].Value = DBNull.Value;
                    parameters1[3].Value = attachObject.FAttachType;
                    parameters1[4].Value = documentModel.FDocId;
                    parameters1[5].Value = attachObject.FAttachFileExt;
                    parameters1[6].Value = attachObject.FEntityNo;
                    parameters1[7].Value = attachObject.FAttachOldFileName;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters1;
                    cmdList.Add(cmds);
                }
            }

            //删除通知对象
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from t_docRecObject ");
            strSql.Append(" where FDocId=@FDocId and FEntityNo=@FEntityNo");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FDocId", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters3[0].Value = documentModel.FDocId;
            parameters3[1].Value = documentModel.FEntityNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            //增加通知对象
            if (docRecObjectList.Count > 0)
            {
                foreach (Model.DocRecObject docRecObject in docRecObjectList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_docRecObject(");
                    strSql.Append("FDocId,FEntityNo,FDeptNo,FEmplNo,FWorkGrpNo)");
                    strSql.Append(" values (");
                    strSql.Append("@FDocId,@FEntityNo,@FDeptNo,@FEmplNo,@FWorkGrpNo)");
                    SqlParameter[] parameters4 = {
                    new SqlParameter("@FDocId", SqlDbType.Decimal,9),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FWorkGrpNo", SqlDbType.NVarChar,12)};
                    parameters4[0].Value = documentModel.FDocId;
                    parameters4[1].Value = documentModel.FEntityNo;
                    parameters4[2].Value = docRecObject.FDeptNo;
                    parameters4[3].Value = docRecObject.FEmplNo;
                    parameters4[4].Value = docRecObject.FWorkGrpNo;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters4;
                    cmdList.Add(cmds);
                }
            }
            //删除合发部门
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from t_documentUnionPubEmpl ");
            strSql.Append(" where FDocId=@FDocId and FEntityNo=@FEntityNo");
            SqlParameter[] parameters5 = {
					new SqlParameter("@FDocId", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters5[0].Value = documentModel.FDocId;
            parameters5[1].Value = documentModel.FEntityNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters5;
            cmdList.Add(cmds);

            //增加合发部门
            if (documentUnionPubEmplList.Count > 0)
            {
                foreach (Model.DocumentUnionPubEmpl docUnionPubEmplModel in documentUnionPubEmplList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_documentUnionPubEmpl(");
                    strSql.Append("FDocId,FEntityNo,FDeptNo,FEmplNo)");
                    strSql.Append(" values (");
                    strSql.Append("@FDocId,@FEntityNo,@FDeptNo,@FEmplNo)");
                    SqlParameter[] parameters6 = {
                            new SqlParameter("@FDocId", SqlDbType.Decimal,9),
                            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters6[0].Value = documentModel.FDocId;
                    parameters6[1].Value = documentModel.FEntityNo;
                    parameters6[2].Value = docUnionPubEmplModel.FDeptNo;
                    parameters6[3].Value = docUnionPubEmplModel.FEmplNo;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters6;
                    cmdList.Add(cmds);
                }
            }

            //删除呈送信息栏目
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from t_DocReference ");
            strSql.Append(" where FDocId=@FDocId and FEntityNo=@FEntityNo");
            SqlParameter[] parameters7 = {
					new SqlParameter("@FDocId", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters7[0].Value = documentModel.FDocId;
            parameters7[1].Value = documentModel.FEntityNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters7;
            cmdList.Add(cmds);

            //增加呈送信息栏目
            if (docReferenceList.Count > 0)
            {
                foreach (Model.DocReference docReferenceModel in docReferenceList)
                {
                    if (docReferenceModel.FDocClsCd == documentModel.FDocClsCd)
                    {
                        continue;
                    }
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_DocReference(");
                    strSql.Append("FDocId,FEntityNo,FDocClsCd)");
                    strSql.Append(" values (");
                    strSql.Append("@FDocId,@FEntityNo,@FDocClsCd)");
                    SqlParameter[] parameters8 = {
                            new SqlParameter("@FDocId", SqlDbType.Decimal,9),
                            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                            new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25)};
                    parameters8[0].Value = documentModel.FDocId;
                    parameters8[1].Value = documentModel.FEntityNo;
                    parameters8[2].Value = docReferenceModel.FDocClsCd; ;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters8;
                    cmdList.Add(cmds);
                }
            }

            //文档查看权限
            //先删除原来的权限语句
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("DELETE FROM dbo.t_documentAuthority WHERE FDocId=@FDocId");
            parameters = new SqlParameter[] {
					new SqlParameter("@FDocId", SqlDbType.Decimal,9)};
            parameters[0].Value = documentModel.FDocId;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //再添加新的权限语句
            if (documentAuthorityList.Count > 0)
            {
                foreach (Model.documentAuthority documentAuthorityModel in documentAuthorityList)
                {
                    cmds = new CommandInfo();
                    strSql = new StringBuilder();
                    strSql.Append("insert into t_documentAuthority(");
                    strSql.Append("FPronoun,FDocId,FSourceNo,FProp)");
                    strSql.Append(" values (");
                    strSql.Append("@FPronoun,@FDocId,@FSourceNo,@FProp)");
                    parameters = new SqlParameter[] {
					new SqlParameter("@FPronoun", SqlDbType.NVarChar,25),
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FSourceNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FProp", SqlDbType.Char,1)};
                    parameters[0].Value = documentAuthorityModel.FPronoun;
                    parameters[1].Value = documentModel.FDocId;
                    parameters[2].Value = documentAuthorityModel.FSourceNo;
                    parameters[3].Value = documentAuthorityModel.FProp;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }

            //执行存储过程，生成临时表数据，以便查询时调用 
            strSql = new StringBuilder();
            cmds = new CommandInfo();
            strSql.Append("EXEC sp_genDocumnetAuthorityDW ");

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = new SqlParameter[] { };
            cmdList.Add(cmds);


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithIndentity(cmdList, 30 * 60);
            }
        }
        /// <summary>
        /// 更新数据的信息类别
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// <param name="docId">信息编号</param>
        /// <param name="docClsCd">信息类别编号</param>
        /// </summary>
        public void UpdateDocClsCd(decimal docId, string docClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE t_document SET FDocClsCd=@FDocClsCd WHERE FDocId=@FDocId");

            SqlParameter[] parameters = {
				new SqlParameter("@FDocClsCd", SqlDbType.VarChar,25),
                    new SqlParameter("@FDocId", SqlDbType.Decimal)};
            parameters[0].Value = docClsCd;
            parameters[1].Value = docId;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 信息置顶,并修改该类下其他信息的置顶顺序(事物模式)
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        /// <param name="docIdList">信息编号列表</param>
        /// <param name="isTop">置顶 1-是 0-否</param>
        public void UpdateTop(List<decimal> docIdList, string isTop)
        {
            List<CommandInfo> commandInfoList = new List<CommandInfo>();
            CommandInfo commandInfo = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };
            int docCount = docIdList.Count;
            int t = 0;
            foreach (decimal decDocId in docIdList)
            {
                t++;
                strSql = new StringBuilder();
                strSql.Append("update t_document set ");
                strSql.Append("FIsTop=@FIsTop,");
                strSql.Append("FTopSeq=@FTopSeq");
                strSql.Append(" where FDocId=@FDocId ");
                parameters = new SqlParameter[] { 	
					new SqlParameter("@FDocId", SqlDbType.Decimal,9),
					new SqlParameter("@FIsTop", SqlDbType.NVarChar,1),
                    new SqlParameter("@FTopSeq", SqlDbType.Int,4)};
                parameters[0].Value = decDocId;
                parameters[1].Value = isTop;
                parameters[2].Value = t - docCount;

                commandInfo = new CommandInfo(strSql.ToString(), parameters);
                commandInfoList.Add(commandInfo);
            }
            if (isTop == "1")
            {
                //修改该类下的所有的信息的置顶顺序+新置顶的条数
                if (docCount > 0)
                {
                    strSql = new StringBuilder();
                    strSql.Append("update t_document set ");
                    strSql.Append("FTopSeq=FTopSeq+");
                    strSql.Append(docCount.ToString());
                    strSql.Append(" where FEntityNo=(SELECT FEntityNo FROM t_Document WHERE FDocId=@FDocId)");
                    strSql.Append("AND FIsTop=1 AND FDocClsCd=(SELECT FDocClsCd FROM t_Document WHERE FDocId=@FDocId)");
                    parameters = new SqlParameter[] { 	
					new SqlParameter("@FDocId", SqlDbType.Decimal,9)};
                    parameters[0].Value = docIdList[0];
                    commandInfo = new CommandInfo(strSql.ToString(), parameters);
                    commandInfoList.Add(commandInfo);
                }
            }
            if (commandInfoList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(commandInfoList, 100);
            }
        }
        /// <summary>
        /// 获得某一类别的已置顶的数据列表，字段 FTitle，FDocId
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        public DataSet GetIsTopList(string docClsCd, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FTitle FROM t_document");
            strSql.Append(" where  FDocClsCd=@FDocClsCd and FEntityNo=@FEntityNo and FIsTop=1 order by FTopSeq");
            SqlParameter[] parameters = {
					new SqlParameter("@FDocClsCd", SqlDbType.VarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docClsCd;
            parameters[1].Value = entityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 信息置顶排序
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        /// <param name="docIdList">信息列表</param>
        public void UpdateDocTopSeq(List<decimal> docIdList)
        {
            List<CommandInfo> commandInfoList = new List<CommandInfo>();
            CommandInfo commandInfo = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };

            int intTopSeq = 0;
            foreach (decimal docId in docIdList)
            {
                intTopSeq++;
                strSql = new StringBuilder();
                strSql.Append("update t_document set FTopSeq=@FTopSeq where FDocId=@FDocId");
                parameters = new SqlParameter[] { 	
					new SqlParameter("@FTopSeq", SqlDbType.Int,4),
                    new SqlParameter("@FDocId", SqlDbType.Decimal)};
                parameters[0].Value = intTopSeq;
                parameters[1].Value = docId;

                commandInfo = new CommandInfo(strSql.ToString(), parameters);
                commandInfoList.Add(commandInfo);
            }
            if (commandInfoList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(commandInfoList);
            }
        }

        /// <summary>
        /// 是否可以删除
        /// 未审批并且不在回收站
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        /// <param name="docId">信息编号</param>
        /// <returns>true或者false</returns>
        public bool isCanDelte(decimal docId)
        {
            bool returnValue=false;
            Model.Document documentModel = GetModel(docId);
            if (documentModel != null)
            {
                if (documentModel.FRecycle == "N")
                {
                    if (documentModel.FStatus == "N")
                    {
                        returnValue = true;
                    }
                    else
                    {
                        DAL.DocCls docClsDAL = new DocCls();
                        Model.DocCls docClsModel = docClsDAL.GetModel(documentModel.FEntityNo,documentModel.FDocClsCd);
                        if (docClsModel != null)
                        {
                            if (docClsModel.FIsNeedAudit == "Y")
                            {
                                returnValue = false;
                            }
                            else
                            {
                                returnValue = true;
                            }
                        }
                        else
                        {
                            returnValue = false;
                        }
                    }
                }
                else
                {
                    returnValue=false;
                }

                //if (documentModel.FStatus == "N" && documentModel.FRecycle == "N")
                //{
                //    return true;
                //}
                //else
                //{
                //    if (documentModel.FStatus == "Y" && documentModel.FRecycle == "N"
                //}
            }
            else
            {
                returnValue=false;
            }
            return returnValue;

            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("select count(1) from t_document");
            //strSql.Append(" where FDocId=@FDocId  and (FStatus='N' OR (FStatus='Y' AND (SELECT FIsNeedAudit FROM t_DocCls "+
            //    " WHERE ) and FRecycle='N' ");
            //SqlParameter[] parameters = {
            //        new SqlParameter("@FDocId", SqlDbType.Decimal)
            //        };
            //parameters[0].Value = docId;

            //if (DbHelperSQL.Exists(strSql.ToString(), parameters))
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }
        /// <summary>
        /// 信息放入回收站
        /// <creator>wangl</creator>
        /// <date>2013-08-20</date> 
        /// </summary>
        /// <param name="docIdList">信息编号列表</param>
        /// <param name="delEmplNo">删除员工编号</param>
        public void UpdateDocumentRecycle(List<decimal> docIdList, string delEmplNo)
        {
            List<CommandInfo> commandInfoList = new List<CommandInfo>();
            CommandInfo commandInfo = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };
            foreach (decimal docId in docIdList)
            {
                strSql = new StringBuilder();
                strSql.Append("UPDATE t_document SET FRecycle='Y',FDelEmplNo=@FDelEmplNo,FDelDate=GETDATE()");
                strSql.Append(" WHERE FDocId=@FDocId");
                parameters = new SqlParameter[] { 	
					new SqlParameter("@FDocId", SqlDbType.Decimal),
                    new SqlParameter("@FDelEmplNo", SqlDbType.NVarChar,15)};
                parameters[0].Value = docId;
                parameters[1].Value = delEmplNo;

                commandInfo = new CommandInfo(strSql.ToString(), parameters);
                commandInfoList.Add(commandInfo);
            }
            if (commandInfoList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(commandInfoList);
            }
        }
        //public DataSet GetNoticeNotRead()
        //{

        //}

        /// <summary>
        /// 获得所有需要考核的信息(已录用，未删除，信息考核分已定义)
        /// <creator>sunlj</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        /// <param name="strEntityNo">单位编号</param>
        /// <param name="decYear">年度</param>
        /// <param name="strQuarter">季度</param>
        /// <returns></returns>
        public DataSet getDocByScore(string strEntityNo, decimal decYear, string strQuarter)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDocClsCd,FDeptNo,FEmplNo,FEmpName from v_document");
            strSql.Append(" where FEntityNo=@FEntityNo and FRecycle='N' and FIsEnroll='Y' and FDocClsCd in(select FDocClsCd from t_docClsScore where FEntityNo=@FEntityNo and FYear=@FYear and FIsScore=1) and ");
            strSql.Append(strQuarter);
            SqlParameter[] parameters = {
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = decYear;
            parameters[1].Value = strEntityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得所有需要考核的信息(包括未录用的),主要用于统计投稿数量
        /// <creator>sunlj</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        /// <param name="strEntityNo">单位编号</param>
        /// <param name="decYear">年度</param>
        /// <param name="strQuarter">季度</param>
        /// <returns></returns>
        public DataSet getDocByScoreAll(string strEntityNo, decimal decYear, string strQuarter)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDocClsCd,FDeptNo,FEmplNo  from t_document");
            strSql.Append(" where FEntityNo=@FEntityNo and FRecycle='N' and FDocClsCd in(select FDocClsCd from t_docClsScore where FEntityNo=@FEntityNo and FYear=@FYear and FIsScore=1) and ");
            strSql.Append(strQuarter);
            SqlParameter[] parameters = {
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = decYear;
            parameters[1].Value = strEntityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取有合发情况的文档，只包括已录用的
        /// <creator>sunlj</creator>
        /// <creator>2013-10-16</creator>
        /// </summary>
        /// <param name="strEntityNo">单位编号</param>
        /// <param name="strQuarter">季度查询条件语句</param>
        /// <returns></returns>
        public DataSet GetDocByHF(string strEntityNo, string strQuarter)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDeptNo,FDocClsCd from v_document where FRecycle='N' and FIsEnroll='Y' and FDocId in (select distinct FDocId from t_documentUnionPubEmpl) and FEntityNo=@FEntityNo and ");
            strSql.Append(strQuarter);
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = strEntityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表,包括未录用,未删除
        /// <creator>sunlj</creator>
        /// <date>2103-10-17</date>
        /// </summary>
        public DataSet GetDocByHFAll(string strEntityNo, string strQuarter)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDeptNo,FDocClsCd from v_document where FRecycle='N' and FDocId in (select distinct FDocId from t_documentUnionPubEmpl) and FEntityNo=@FEntityNo and ");
            strSql.Append(strQuarter);
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = strEntityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取某部门的所有需要考核的信息(未放入回收站,已录用的数据)的某几个字段 FDocId,FDocClsCd,FDeptNo,FEmplNo,FTitle,FPubDate,FEmpName
        /// <creator>sunlj</creator>
        /// <date>2013-10-19</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decYear"></param>
        /// <param name="strEmplNo"></param>
        /// <returns></returns>
        public DataSet getDocByChkInfoAuditEntryByDept(string strEntityNo, decimal decYear, string strDeptNo, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDocClsCd,FDocClsName,FDeptNo,FEmplNo,FTitle,FPubDate,FEmpName from v_document");
            strSql.Append(" where FEntityNo=@FEntityNo and FRecycle='N' and FIsEnroll='Y'  and FDeptNo=@FDeptNo and FDocClsCd in(select FDocClsCd from t_docClsScore where FEntityNo=@FEntityNo and FYear=@FYear and FIsScore=1) ");
            if (strWhere != "")
            {
                strSql.Append("and" + strWhere);
            }
            else
            {
                strSql.Append("and FDisplayDate between '" + decYear + "' and '");
                strSql.Append((decYear + 1) + "' ");
            }
            strSql.Append("or FDocId in (select distinct FDocId from t_documentUnionPubEmpl where FDeptNo=@FDeptNo and FDocId in (select FDocId from t_document where FRecycle='N' and FIsEnroll='Y'");
            if (strWhere != "")
            {
                strSql.Append("and" + strWhere);
            }
            else
            {
                strSql.Append("and FDisplayDate between '" + decYear + "' and '");
                strSql.Append((decYear + 1) + "' ");
            }
            strSql.Append(" and FDocClsCd in(select FDocClsCd from t_docClsScore where FEntityNo=@FEntityNo and FYear=@FYear and FIsScore=1)))");

            strSql.Append(" order by FPubDate");
            SqlParameter[] parameters = {
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = decYear;
            parameters[1].Value = strEntityNo;
            parameters[2].Value = strDeptNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 更新数据的jcms信息
        /// <creator>wangl</creator>
        /// <date>2013-11-20</date> 
        /// <param name="docId">信息编号</param>
        /// <param name="isPubJCMS">是否推送到JCMS Y,N</param>
        /// <param name="parallelDocClsCd">信息类别对应JCMS编号</param>
        /// </summary>
        public void UpdateJcms(decimal docId,string isPubJCMS, string parallelDocClsCd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE t_document SET FIsPubJCMS=@FIsPubJCMS,FParallelDocClsCd=@FParallelDocClsCd WHERE FDocId=@FDocId");
            SqlParameter[] parameters = {
				
                    new SqlParameter("@FDocId", SqlDbType.Decimal),
                    new SqlParameter("@FIsPubJCMS", SqlDbType.Char,1),
                    new SqlParameter("@FParallelDocClsCd", SqlDbType.NVarChar,25)
                                        };
            parameters[0].Value = docId;
            parameters[1].Value = isPubJCMS;
            parameters[2].Value = parallelDocClsCd;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        


    }

}
